set more off
capture log close

//  program:    AnanatEtAl_test_score_preGR
//  task:		Run Regressions for test score results for a subsample of years prior to the Great Recession

//change working directory to point to the file with the data
cd *** Fill in path name here ***

//create log file
log using AnanatEtAl_test_score_preGR, replace text

//load the merged bls naep data
use AnanatEtAl_test_score_data, clear

//keep observations for test-taking years 1996, 2000, 2003, 2005, 2007
keep if year<2009

//set the panel variables
xtset stateno year

//run regressions using test-taker sample sizes as frequency weights

** All Students **
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag) [fweight=sample_size], vce(cluster stateno) first
est store ALL
outreg2 [ALL] using test_score_preGR, drop(yrd* stated*) excel replace dec(3)

** Black Students **
ivregress 2sls z_black yrd* stated* (seppctyrlag = ticpctyrlag) [fweight=n_black], vce(cluster stateno) first
est store BLACK
outreg2 [BLACK] using test_score_preGR, drop(yrd* stated*) excel dec(3) 

** White Students **
ivregress 2sls z_white yrd* stated* (seppctyrlag = ticpctyrlag) [fweight=n_white], vce(cluster stateno) first
est store WHITE
outreg2 [WHITE] using test_score_preGR, drop(yrd* stated*) excel dec(3)

** State-years with below median unemployment **
//generate the median unemployment cutoff
sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag<=cutoff
//run regression weighted by test-taker sample size
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag) [fweight=sample_size], vce(cluster stateno) first
est store LOWUNEMP
outreg2 [LOWUNEMP] using test_score_preGR, drop(yrd* stated*) excel dec(3)

clear all

** State-years with above median unemployment **
//load the data
use AnanatEtAl_test_score_data, clear

//keep observations for test-taking years 1996, 2000, 2003, 2005, 2007
keep if year<2009

//set the panel variables
xtset stateno year

//generate the median unemployment cutoff value
sort year
by year: egen cutoff = pctile(unemplag), p(50)
keep if unemplag>cutoff

//run regression weighted by test-taker sample size
ivregress 2sls z_all yrd* stated* (seppctyrlag = ticpctyrlag) [fweight=sample_size], vce(cluster stateno) first
est store HIGHUNEMP
outreg2 [HIGHUNEMP] using test_score_preGR, drop(yrd* stated*) excel dec(3)

clear all

log close


